package 多线程.死锁;

public class DiedLock {
    public static void main(String[] args) throws InterruptedException {
        String resourse1 = "resourse1";
        String resourse2 = "resourse2";

        new Thread(()->{
            synchronized (resourse1){
                System.out.println("拿到了资源"+resourse1);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (resourse2){
                    System.out.println("拿到了资源"+resourse2);
                }
            }
        }).start();

        new Thread(()->{
            synchronized (resourse2){
                System.out.println("拿到了资源"+resourse2);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (resourse1){
                    System.out.println("拿到了资源"+resourse1);
                }
            }
        }).start();
    }
}
